package com.soft.javase.day06;

import java.time.LocalDateTime;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/24
 */
public class News {
    private String title;
    private String content;
    private LocalDateTime time;

    public News(String title, String content, LocalDateTime time) {
        this.title = title;
        this.content = content;
        this.time = time;
    }

    public LocalDateTime getTime() {
        return time;
    }

    @Override
    public String toString() {
        return "News{" +
                "title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", time=" + time +
                '}';
    }

    private static void bubbleSortByTime(News[] array) {
        int n = array.length;
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (array[j].getTime().isBefore(array[j + 1].getTime())) {
                    News temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        News[] newsArray = new News[10];
        newsArray[0] = new News("Java 17发布", "Oracle发布了Java 17 LTS版本...", LocalDateTime.of(2021, 9, 14, 10, 0,0));
        newsArray[1] = new News("Spring Boot 3.0", "Spring框架推出新版本...", LocalDateTime.of(2022, 11, 24, 9, 30,0));
        newsArray[2] = new News("人工智能新突破", "研究人员在AI领域取得重大进展...", LocalDateTime.of(2023, 3, 15, 14, 15,1));
        newsArray[3] = new News("全球气候峰会", "各国领导人讨论气候变化问题...", LocalDateTime.of(2023, 1, 20, 16, 45,2));
        newsArray[4] = new News("世界杯决赛", "阿根廷队获得世界杯冠军...", LocalDateTime.of(2022, 12, 18, 18, 0,5));
        newsArray[5] = new News("科技公司裁员", "多家科技巨头宣布裁员计划...", LocalDateTime.of(2023, 2, 5, 11, 20,5));
        newsArray[6] = new News("新能源车销量", "电动汽车市场占有率创新高...", LocalDateTime.of(2023, 4, 10, 13, 10,9));
        newsArray[7] = new News("太空探索进展", "NASA公布新的太空探索计划...", LocalDateTime.of(2022, 10, 5, 12, 30,12));
        newsArray[8] = new News("经济复苏信号", "全球经济显现复苏迹象...", LocalDateTime.of(2023, 5, 1, 8, 45,24));
        newsArray[9] = new News("教育改革方案", "教育部发布新的教育改革方案...", LocalDateTime.of(2022, 9, 1, 15, 0,27));

        bubbleSortByTime(newsArray);

        for (News news : newsArray) {
            System.out.println(news);
        }
    }

}
